/**
 * <p>
 * 版权所有：中企动力
 * </p>
 * <p>
 * 未经本公司许可，不得以任何方式复制或使用本程序任何部分
 * </p>
 */
package com.ce.pms.report.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ce.pms.charge.dao.IFeeBankDao;
import com.ce.pms.charge.dao.IPeriodDao;
import com.ce.pms.charge.model.PeriodDomain;
import com.ce.pms.report.dao.IReportDao;
import com.ce.pms.report.queryvo.BankPrepaidListQueryVO;
import com.ce.pms.report.queryvo.BankUnpaidListQueryVO;
import com.ce.pms.report.vo.BankPrepaidListVo;
import com.ce.report.entity.CEReportDataSet;
import com.ce.report.exception.CEReportException;
import com.ce.report.service.ICEReportDataSetService;
import com.ce.report.vo.ReportsQueryBaseVo;
import com.ce.util.BlankUtil;
import com.ce.util.DateUtil;

/**
 * 银行已扣款清单
 *
 * @author <a href="mailto:i0o@live.cn">黄腾飞</a>
 * @Created 2008-11-13
 */

public class BankPrepaidListService implements ICEReportDataSetService {

	private IReportDao reportDao;

	private IFeeBankDao feeBankDao;


	public CEReportDataSet getReportDataSet(ReportsQueryBaseVo arg0)
			throws CEReportException {
		BankPrepaidListQueryVO queryVO = (BankPrepaidListQueryVO) arg0;
		return new CEReportDataSet(getData(queryVO),getHeadInfo(queryVO));
	}

	/**
	 * 功能描述:查询数据列表  <br>
	 * @param queryVO
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2009-11-28  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private List<BankPrepaidListVo> getData(BankPrepaidListQueryVO queryVO){
		String precinct = queryVO.getPrecinct();
		String bankId = queryVO.getBankId().toString();
		String buildId = "";
		if (BlankUtil.isBlank(queryVO.getBuildingId())){
			buildId = "%";
		}else{
			buildId = queryVO.getBuildingId().toString();
		}

		String period = DateUtil.convertDateToStr(queryVO.getTrustMonth(),"yyyyMM");

		List<Object[]> temp = reportDao.getDataList("bankPrepaidList", new Object[]{period,precinct,buildId,bankId});
		List<BankPrepaidListVo> list = converToReportVoList(temp);

		return list;
	}

	/**
	 * 功能描述:转换 VO  <br>
	 * @param dataList
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2009-11-28  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private List<BankPrepaidListVo> converToReportVoList(List<Object[]> dataList) {
		if (BlankUtil.isBlank(dataList)){
			return null;
		}

		List<BankPrepaidListVo> voList = new ArrayList<BankPrepaidListVo>();
		for (Object[] obj : dataList) {
			BankPrepaidListVo tmpVo = new BankPrepaidListVo();
			tmpVo.setHouseNumber((String) obj[0]);
			tmpVo.setUserName((String) obj[1]);
			tmpVo.setAccount((String) obj[2]);
			tmpVo.setTrustMoney((BigDecimal) obj[3]);
			tmpVo.setShouldPay((BigDecimal) obj[4]);

			voList.add(tmpVo);
		}
		return voList;
	}

	/**
	 * 功能描述:获取头信息  <br>
	 * @param queryVO
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-11-28  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private Map<String, Object> getHeadInfo(BankUnpaidListQueryVO queryVO){
		Map<String, Object> map =new HashMap<String, Object>();
		String trustMonth = DateUtil.convertDateToStr(queryVO.getTrustMonth(), "yyyy年MM月");
		map.put("title", trustMonth);
		map.put("reportHeadStr", "托收银行："+ feeBankDao.findById(queryVO.getBankId()).getBankName());
		map.put("printDate", new Date());

		return map;
	}

	public void setReportDao(IReportDao reportDao) {
		this.reportDao = reportDao;
	}

	public void setFeeBankDao(IFeeBankDao feeBankDao) {
		this.feeBankDao = feeBankDao;
	}

}
